﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WXYW.DAL;
using WXYW.Entities;

namespace WXYW.BLL
{
    public class FeedBackService : RepositoryBase
    {
        public IQueryable<Feedback> GetFeedBackForQuarter(int year, int start, int end)
        {
            return GetEntities<Feedback>(f => f.ApplicationForm.FirstOrDefault().ApplicationDateTime.Value.Year == year
                && f.ApplicationForm.FirstOrDefault().ApplicationDateTime.Value.Month >= start
                && f.ApplicationForm.FirstOrDefault().ApplicationDateTime.Value.Month <= end);
        }

        public IQueryable<Feedback> GetFeedBackByYearAndServiceStation(int year, int servicestation)
        {
            return GetEntities<Feedback>(f => f.ApplicationForm.FirstOrDefault().ApplicationDateTime.Value.Year == year
                && f.ApplicationForm.FirstOrDefault().ServiceStation.ID == servicestation);
        }

        public IQueryable<Feedback> GetFeedBackByQuarterAndServiceStation(int year, int start, int end, int servicestation)
        {
            IQueryable<Feedback> fblist = GetFeedBackForQuarter(year, start, end);
            fblist = fblist.Where(f => f.ApplicationForm.FirstOrDefault().ServiceStation.ID == servicestation);
            return fblist;
        }

        public IQueryable<Feedback> GetFeedBackByYearAndProvider(int year, string provider)
        {
            return GetEntities<Feedback>(f => f.ApplicationForm.FirstOrDefault().ApplicationDateTime.Value.Year == year
                && f.ApplicationForm.FirstOrDefault().ApplicationProduct.Where(p => p.ReturnToFactoryForm.FirstOrDefault().ProvideCode == provider).Count() > 0);
        }
    }
}
